package com.zmn.oms.third.jddj;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import org.springframework.stereotype.Component;

/**
 * 京东到家渠道常量定义类
 *
 * @author xiewenbing
 * @date 2021/01/18
 */
@Component
public class JddjConsts {

    /**
     * 渠道名称
     */
    public final static String CHANNEL_NAME = "平台渠道E13（京东到家）";
    public final static String CHANNEL_NAME_QTDJ = "平台渠道E66（青提到家）";

    /**
     * 渠道对接开关
     */
    public static boolean POWER_ON = true;

    /**
     * API协议版本
     */
    public final static String API_VERSION = "1.0";

    /**
     * 交互数据格式
     */
    public final static String API_FORMAT = "json";

    /**
     * APP KEY
     */
    public static String APP_KEY = "750b4ef4850e4ec182b507f7ba9f7452";

    /**
     * APP SECRET
     */
    public static String APP_SECRET = "58fa3fd5fe9d4067994a419ca9e1d60d";

    /**
     * API URL
     */
    public static String API_URL = "https://openapi.jddj.com/mockapi/";

    /**
     * url path - 订单确认
     */
    public final static String PATH_CONFIRM = "bm/open/api/order/printOrder";

    /**
     * url path - 同步拣货完成且顾客自提
     */
    public final static String PATH_ORDER_SELF_MENTION = "bm/open/api/order/OrderSelfMention";

    /**
     * url path - 师傅上门
     */
    public final static String PATH_VISIT = "bm/open/api/order/OrderSerllerDelivery";

    /**
     * url path - 订单完成
     */
    public final static String PATH_COMPLETE = "ocs/deliveryEndOrder";

    /**
     * url path - 订单取消
     */
    public final static String PATH_CANCEL = "orderStatus/cancelAndRefund";

    /**
     * url path - 订单查询
     */
    public final static String PATH_QUERY = "order/es/query";

    /**
     * url path - 订单自提码核验
     */
    public final static String PATH_VERFICATION_CODE = "ocs/checkSelfPickCode";

    /**
     * 商家同意取消申请
     */
    public final static String AGREE_CANCEL_APPLY = "20031";

    /**
     * 商家驳回取消申请
     */
    public final static String REFUSE_CANCLE_APPLY = "20032";

    /**
     * 查询订单返回字段
     */
    public final static String QUERY_RETURN_FIELDS = "orderId,srcInnerType,orderType,orderStatus,orderAgingType,orgCode," +
            "buyerPin,buyerFullName,buyerFullAddress,buyerTelephone,buyerMobile,lastFourDigitsOfBuyerMobile," +
            "orderPayType,payChannel,orderTotalMoney,orderDiscountMoney,orderFreightMoney,orderReceivableFreight,platformPointsDeductionMoney,orderBuyerPayableMoney,orderGoodsMoney," +
            "buyerLng,buyerLat,buyerCity,buyerCityName,buyerCountry,buyerCountryName,orderBuyerRemark," +
            "srcOrderType,srcOrderId,product,orderPreStartDeliveryTime,orderPreEndDeliveryTime,pickDeadline";

    /**
     * 错误码 - 成功
     */
    public final static int RESPONSE_CODE_SUCCESS = 0;

    /**
     * 错误码 - 失败
     */
    public final static int RESPONSE_CODE_FAILED = -1;

    /**
     * 错误码 - 业务重试
     */
    public final static int RESPONSE_CODE_BUSINESS_RETRY = -10000;

    /**
     * 错误码 - 必填项参数未填
     */
    public final static int RESPONSE_CODE_PARAM_DEFECT = 10005;

    /**
     * 错误码 - 无效Token令牌
     */
    public final static int RESPONSE_CODE_INVALID_TOKEN = 10013;

    /**
     * 错误码 - 无效Sign签名
     */
    public final static int RESPONSE_CODE_INVALID_SIGN = 10014;

    /**
     * 错误码 - API参数异常
     */
    public final static int RESPONSE_CODE_PARAM_ERROR = 10015;

    /**
     * 错误码 - 不存在的方法名
     */
    public final static int RESPONSE_CODE_METHOD_ERROR = 10018;

    /**
     * 商品无优惠
     */
    public final static int PRODUCT_NO_DISCOUNT_CODE = 1;

    /**
     * 获取错误消息描述
     *
     * @param code
     * @return
     */
    public static String getErrorMsgByCode(int code) {

        switch (code) {
            case RESPONSE_CODE_SUCCESS:
                return "成功";
            case RESPONSE_CODE_FAILED:
                return "失败";
            case RESPONSE_CODE_BUSINESS_RETRY:
                return "业务重试";
            case RESPONSE_CODE_PARAM_DEFECT:
                return "必填项参数未填";
            case RESPONSE_CODE_INVALID_TOKEN:
                return "无效Token令牌";
            case RESPONSE_CODE_INVALID_SIGN:
                return "无效Sign签名";
            case RESPONSE_CODE_PARAM_ERROR:
                return "API参数异常";
            case RESPONSE_CODE_METHOD_ERROR:
                return "不存在的方法名";
            case 4001001:
                return "输入参数为空";
            case 4001002:
                return "订单信息不存在";
            case 4001003:
                return "越权操作订单";
            case 4001004:
                return "订单状态异常";
            case 10138:
                return "订单已(申请)取消";
            case 10139:
                return "订单已锁定";
            case 10132:
                return "订单已拣货";
            case 1:
                return "参数错误";
            case 4:
                return "订单不存在";
            case 11:
                return "无此操作权限";
        }

        return "未知的错误";
    }

    /******************************动态配置参数**************************************/
    @NacosValue(value = "${jddj.api.powerOn:false}", autoRefreshed = true)
    public void setPowerOn(boolean powerOn) {
        POWER_ON = powerOn;
    }

    @NacosValue(value = "${jddj.api.url:https://openapi.jddj.com/mockapi/}", autoRefreshed = true)
    public void setApiUrl(String apiUrl) {
        API_URL = apiUrl;
    }

    @NacosValue(value = "${jddj.app.secret:58fa3fd5fe9d4067994a419ca9e1d60d}", autoRefreshed = true)
    public void setAppSecret(String appSecret) {
        APP_SECRET = appSecret;
    }

    @NacosValue(value = "${jddj.app.key:750b4ef4850e4ec182b507f7ba9f7452}", autoRefreshed = true)
    public void setAppKey(String appKey) {
        APP_KEY = appKey;
    }
}
